import { Body, Controller, Post } from '@nestjs/common';
import { LoginTdo } from '../dto/login.dto';
import { responseWrapper } from 'src/utils';
import { LoginService } from '../services/login.service';
import { CommonResponse } from 'src/types';
import { ApiCreatedResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
// 测试npm包
import { NestLogService } from 'nest-mlog';

@ApiTags('用户登录')
@Controller('login')
export class LoginController {
  constructor(
    private readonly loginService: LoginService, // private readonly toolsService: ToolsService
    private readonly nestLogService: NestLogService,
  ) {}

  @ApiOperation({
    summary: '用户登录',
    description: '用户名和密码登录',
  })
  @ApiCreatedResponse({
    type: LoginTdo,
    description: '用户登录DTO',
  })
  @Post()
  async login(@Body() data: LoginTdo): Promise<CommonResponse> {
    this.nestLogService.log('mlog登录');
    try {
      const res = await this.loginService.login(data);
      return responseWrapper(res);
    } catch (error) {
      return responseWrapper(error, true);
    }
  }
}
